# _*_ coding: utf-8 _*_
# @Author   : Wei Yue
# @Time     : 2023-04-29 21:04
# @Function :  把cruise仿真数据输出的载荷谱 通过损伤模型转换
import numpy as np
import pandas as pd
import math, os
# 转速按绝对值处理
from cruiseAnalysis.loadSpectrumConstant import *


def exportEMLoadSpectrum(path, spdMin, spdMax, spdStep, trqMin, trqMax, trqStep, timeStep):
    '''
    导出某个工况下的电机载荷谱
    :param path:  cruise导出文件路径
    :param spdMin:  转速最小值
    :param spdMax:  转速最大值
    :param spdStep: 转速步长
    :param trqMin:  转矩最小值
    :param trqMax:  转矩最大值
    :param trqStep:  转矩步长
    :param timeStep:  时间周期步长
    :return: 导出载荷谱excel
    '''
    files = os.listdir(path + '/cruiseDetail/')
    for file in files:
        new_path = os.path.join(path + '/cruiseDetail/' + file)
        out_path = path + '/spectrum/EM/loadSpectrumEMDetail-' + file

        table = pd.read_excel(new_path, index_col=0)
        columns = list(range(spdMin, spdMax + spdStep, spdStep))
        index = list(range(trqMax, trqMin - trqStep, -trqStep))
        loadSpectrum = pd.DataFrame(index=index, columns=columns)
        loadSpectrum.fillna(0, inplace=True)
        # 统计电机的转速 转矩点
        for value in table.values:
            torque = value[EMtrqIndex]
            speed = value[EMspdIndex]
            if torque == 0:
                continue
            if isAbsSpd:
                speed = math.fabs(speed)
            # 边界值处理
            torque = saturation(torque, trqMin, trqMax)
            speed = saturation(speed, spdMin, spdMax)
            x = round(abs(torque - trqMax) / trqStep)
            y = round((speed - spdMin) / spdStep)
            loadSpectrum.iloc[x, y] = loadSpectrum.iloc[x, y] + timeStep
        loadSpectrum.to_excel(out_path,engine='xlsxwriter')
    print('生成电机载荷谱完成！')


def exportVehicleLoadSpectrum(path, veloMin, veloMax, veloStep, trqMin, trqMax, trqStep, timeStep):
    '''
        导出某个工况下的车速载荷谱
        :param path:  cruise导出文件路径
        :param veloMin:  车速最小值 kph
        :param veloMax:  车速最大值
        :param veloStep: 车速步长
        :param trqMin:  减速器输出转矩最小值
        :param trqMax:  转矩最大值
        :param trqStep:  转矩步长
        :param timeStep:  时间周期步长
        :return: 导出载荷谱excel
        '''
    files = os.listdir(path + '/cruiseDetail/')
    for file in files:
        new_path = os.path.join(path + '/cruiseDetail/' + file)
        out_path = path + '/spectrum/VEHICLE/loadSpectrumVehicleDetail-' + file
        table = pd.read_excel(new_path, index_col=0)
        columns = list(range(veloMin, veloMax + veloStep, veloStep))
        index = list(range(trqMax, trqMin - trqStep, -trqStep))
        loadSpectrum = pd.DataFrame(index=index, columns=columns)
        # loadSpectrum.fillna(0, inplace=True)
        pd.set_option('future.no_silent_downcasting', True)
        loadSpectrum = loadSpectrum.fillna(0)
        # 统计汽车的车速和转矩点
        for value in table.values:
            torque = value[VtrqIndex]
            velocity = value[VelocityIndex]
            if abs(torque) <= 1e-5:
                continue
            if isAbsSpd:
                velocity = math.fabs(velocity)
            # 边界值处理
            torque = saturation(torque, trqMin, trqMax)
            velocity = saturation(velocity, veloMin, veloMax)
            x = round(abs(torque - trqMax) / trqStep)
            y = round((velocity - veloMin) / veloStep)
            loadSpectrum.iloc[x, y] = loadSpectrum.iloc[x, y] + timeStep
        loadSpectrum.to_excel(out_path,engine='xlsxwriter')
    print('生成车速载荷谱完成！')


def exportDCLoadSpectrum(path, volMin, volMax, VolStep, curMin, curMax, curStep, timeStep):
    '''
    导出某个工况下的DC载荷谱
    :param path:  cruise导出文件路径
    :param volMin:  电压最小值
    :param volMax:  电压最大值
    :param VolStep: 电压步长
    :param curMin:  电流最小值
    :param curMax:  电流最大值
    :param curStep:  电流步长
    :param timeStep:  时间周期步长
    :return: 导出载荷谱excel
    '''
    files = os.listdir(path + '/cruiseDetail/')
    for file in files:
        new_path = os.path.join(path + '/cruiseDetail/' + file)
        out_path = path + '/spectrum/DC/loadSpectrumDCDetail-' + file

        table = pd.read_excel(new_path, index_col=0)
        columns = list(range(volMin, volMax + VolStep, VolStep))
        index = list(range(curMax, curMin - curStep, -curStep))
        loadSpectrum = pd.DataFrame(index=index, columns=columns)
        loadSpectrum.fillna(0, inplace=True)
        # 统计DC的电压电流点
        for value in table.values:
            voltage = value[volIndex]
            current = value[dcCurIndex]
            # 边界值处理
            current = saturation(current, curMin, curMax)
            voltage = saturation(voltage, volMin, volMax)
            x = round(abs(current - curMax) / curStep)
            y = round((voltage - volMin) / VolStep)
            loadSpectrum.iloc[x, y] = loadSpectrum.iloc[x, y] + timeStep
        loadSpectrum.to_excel(out_path,engine='xlsxwriter')
    print('生成DC载荷谱完成！')


def exportACLoadSpectrum(path, FreMin, FreMax, FreStep, curMin, curMax, curStep, timeStep):
    '''
       导出某个工况下的DC载荷谱
       :param path:  cruise导出文件路径
       :param FreMin:  频率最小值
       :param FreMax:  频率最大值
       :param FreStep: 频率步长
       :param curMin:  电流最小值
       :param curMax:  电流最大值
       :param curStep:  电流步长
       :param timeStep:  时间周期步长
       :return: 导出载荷谱excel
       '''
    files = os.listdir(path + '/cruiseDetail/')
    for file in files:
        new_path = os.path.join(path + '/cruiseDetail/' + file)
        out_path = path + '/spectrum/AC/loadSpectrumACDetail-' + file

        table = pd.read_excel(new_path, index_col=0)
        columns = list(range(FreMin, FreMax + FreStep, FreStep))
        index = list(range(curMax, curMin - curStep, -curStep))
        loadSpectrum = pd.DataFrame(index=index, columns=columns)
        loadSpectrum.fillna(0, inplace=True)
        # 统计AC
        for value in table.values:
            fre = value[freIndex]
            current = value[acCurIndex]
            # 边界值处理
            current = saturation(current, curMin, curMax)
            fre = saturation(fre, FreMin, FreMax)
            x = round(abs(current - curMax) / curStep)
            y = round((fre - FreMin) / FreStep)
            loadSpectrum.iloc[x, y] = loadSpectrum.iloc[x, y] + timeStep
        loadSpectrum.to_excel(out_path,engine='xlsxwriter')
    print('生成AC载荷谱完成！')


def statisticLoadSpectrum(path):
    files = os.listdir(path + '/cruiseDetail/')
    statsticColumns = ['VMin', 'VMean', 'VMax', 'SpdMin', 'SpdMean', 'SpdMax',
                       'TrqMin', 'TrqMean', 'TrqMax',
                       'ACMin', 'ACMean', 'ACMax',
                       'DcMin', 'DcMean', 'DcMax',
                       'ACpwrMin', 'ACpwrMean', 'ACpwrMax',
                       'ACpwr_L:0-50', 'ACpwr_L-M:50-100', 'ACpwr_M:100-150', 'ACpwr_M-H:150-200', 'ACpwr_H:>200',
                       'GBpwrMin', 'GBpwrMean', 'GBpwrMax',
                       'GBpwr_L:0-50', 'GBpwr_L-M:50-100', 'GBpwr_M:100-150', 'GBpwr_M-H:150-200', 'GBpwr_H:>200',
                       'Average_Eff']
    statisticDf = pd.DataFrame(index=files, columns=statsticColumns)
    out_statistic_path = path + '/statistic/loadSpectrumStatistic.xlsx'
    for file in files:
        new_path = os.path.join(path + '/cruiseDetail/' + file)
        table = pd.read_excel(new_path)
        # 统计
        # 车辆速度abs min ave max ; 电机转速abs min ave max; 电机转矩abs min ave max;
        # AC电流 min ave max; DC电压 min ave max;
        # AC功率abs min ave max, ACpwr_L:0-50, ACpwr_L-M:50-100, ACpwr_M:100-150, ACpwr_M-H:150-200, ACpwr_H:>200
        # 减速器功率abs  min ave max ,GBpwr_L:0-50, GBpwr_L-M:50-100, GBpwr_M:100-150, GBpwr_M-H:150-200, GBpwr_H:>200
        velocity = table.loc[:, 'VELOCITY'].abs()
        emSpd = table.loc[:, 'SPEED'].abs()
        emTrq = table.loc[:, 'TORQUE'].abs()
        ACcurrent = table.loc[:, 'I_AC'].abs()
        dcVoltage = table.loc[:, 'VOLTAGE']
        ACpwr = table.loc[:, 'ACpwr'].abs()
        GBpwr = table.loc[:, 'P_GB'].abs()
        elePwr = table.loc[:, 'ELECTRICAL_POWER']
        sections = [-1e-5, 50, 100, 150, 200, 10000]
        # 对AC功率做范围统计 ACpwr_L:0-50, ACpwr_L-M:50-100, ACpwr_M:100-150, ACpwr_M-H:150-200, ACpwr_H:>200
        group_ACpwr_names = ['ACpwr_L:0-50', 'ACpwr_L-M:50-100', 'ACpwr_M:100-150', 'ACpwr_M-H:150-200', 'ACpwr_H:>200']
        ACpwr_cuts = pd.cut(np.array(GBpwr.values), sections, labels=group_ACpwr_names)
        # ACpwr_counts = pd.value_counts(ACpwr_cuts)
        ACpwr_counts = pd.Series(ACpwr_cuts).value_counts()
        ACpwr_totalCount = sum(dict(ACpwr_counts).values())
        ACpwr1 = dict(ACpwr_counts)['ACpwr_L:0-50'] / ACpwr_totalCount
        ACpwr2 = dict(ACpwr_counts)['ACpwr_L-M:50-100'] / ACpwr_totalCount
        ACpwr3 = dict(ACpwr_counts)['ACpwr_M:100-150'] / ACpwr_totalCount
        ACpwr4 = dict(ACpwr_counts)['ACpwr_M-H:150-200'] / ACpwr_totalCount
        ACpwr5 = dict(ACpwr_counts)['ACpwr_H:>200'] / ACpwr_totalCount
        # 对GBpwr范围统计 ,GBpwr_L:0-50, GBpwr_L-M:50-100, GBpwr_M:100-150, GBpwr_M-H:150-200, GBpwr_H:>200
        group_GBpwr_names = ['GBpwr_L:0-50', 'GBpwr_L-M:50-100', 'GBpwr_M:100-150', 'GBpwr_M-H:150-200', 'GBpwr_H:>200']
        GBpwr_cuts = pd.cut(np.array(GBpwr.values), sections, labels=group_GBpwr_names)
        # GBpwr_counts = pd.value_counts(GBpwr_cuts)
        GBpwr_counts = pd.Series(GBpwr_cuts).value_counts()
        GBpwr_totalCount = sum(dict(GBpwr_counts).values())
        GBpwr1 = dict(GBpwr_counts)['GBpwr_L:0-50'] / GBpwr_totalCount
        GBpwr2 = dict(GBpwr_counts)['GBpwr_L-M:50-100'] / GBpwr_totalCount
        GBpwr3 = dict(GBpwr_counts)['GBpwr_M:100-150'] / GBpwr_totalCount
        GBpwr4 = dict(GBpwr_counts)['GBpwr_M-H:150-200'] / GBpwr_totalCount
        GBpwr5 = dict(GBpwr_counts)['GBpwr_H:>200'] / GBpwr_totalCount

        ##计算效率########### todo 这里有问题
        machPwr = table.loc[:, 'TORQUE_OUTPUT'] * table.loc[:, 'SPEED_OUTPUT'] * 2 * 3.1415926 / 60 / 1000
        genMachPwr = machPwr.copy()
        motMachPwr = machPwr.copy()
        genMachPwr[genMachPwr > 0] = 0
        motMachPwr[motMachPwr < 0] = 0
        genElePwr = elePwr.copy()
        motElePwr = elePwr.copy()
        genElePwr[genElePwr > 0] = 0
        motElePwr[motElePwr < 0] = 0
        average_Eff = (motMachPwr.sum() - genElePwr.sum()) / (motElePwr.sum() - genMachPwr.sum())
        ################################################
        statistic = [velocity.min(), velocity.mean(), velocity.max(),
                     emSpd.min(), emSpd.mean(), emSpd.max(),
                     emTrq.min(), emTrq.mean(), emTrq.max(),
                     ACcurrent.min(), ACcurrent.mean(), ACcurrent.max(),
                     dcVoltage.min(), dcVoltage.mean(), dcVoltage.max(),
                     ACpwr.min(), ACpwr.mean(), ACpwr.max(), ACpwr1, ACpwr2, ACpwr3, ACpwr4, ACpwr5,
                     GBpwr.min(), GBpwr.mean(), GBpwr.max(), GBpwr1, GBpwr2, GBpwr3, GBpwr4, GBpwr5, average_Eff]
        statisticDf.loc[file] = statistic
    statisticDf.to_excel(out_statistic_path)
    print('分别统计完成！')


def testMath():
    # 向上取整
    spd = math.ceil((250 - 250) / 500)
    torq = math.ceil((-412 - -415) / 10)
    trq2 = round((-412 - -415) / 10)
    print(spd)
    print(torq)
    print(trq2)


def saturation(input, min, max):
    if (input < min):
        input = min
    if (input > max):
        input = max
    return input


def getClosestPosition(trqList, spdList, index, column):
    closed_trq = trqList[0]
    closed_spd = spdList[-1]
    for trq in trqList:
        if abs(index - trq) < abs(index - closed_trq):
            closed_trq = trq
    for spd in spdList:
        if abs(column - spd) < abs(column - closed_spd):
            closed_spd = spd
    return closed_trq, closed_spd

# 往更大值的方向转换
def getClosestPosition_M(trqList, spdList, index, column):
    if index <0:
        closed_trq = trqList[0]
    else:
        closed_trq = trqList[-1]

    if column <0:
        closed_spd = spdList[0]
    else:
        closed_spd = spdList[-1]

    for trq in trqList:
        if abs(index - trq) < abs(index - closed_trq):
            if (0 < index <= trq) or (0 > index >= trq):
                closed_trq = trq
    for spd in spdList:
        if abs(column - spd) < abs(column - closed_spd):
            if (0 < column <= spd) or (0 > column >= spd):
                closed_spd = spd
    return closed_trq, closed_spd


def tranferToPoints(path, trqList, spdList, pList):
    '''
    等效转换
    :param trqList: 欲转换的转矩集合
    :param spdList: 欲转换的转速集合
    :return: 转换后生成的文档
    '''
    files = os.listdir(path + '/spectrum/')
    for file in files:
        if not file.endswith('.xlsx'):
            continue
        new_path = os.path.join(path + '/spectrum/' + file)
        table = pd.read_excel(new_path, sheet_name='EM', index_col=0)
        for p in pList:
            out_path = path + '/durability/' + 'durability-' + str(p) + '-' + file
            outputDf = pd.DataFrame(index=trqList, columns=spdList, dtype='float64')
            outputDf.fillna(0, inplace=True)
            pCoeffient = 0
            for index in table.index.values:
                for column in table.columns.values:
                    time1 = table.loc[index][column]
                    if time1 == 0:
                        continue
                    column = math.fabs(column)
                    out_index, out_col = getClosestPosition_M(trqList, spdList, index, column)
                    trq1 = index
                    spd1 = column
                    trq2 = out_index
                    spd2 = out_col
                    time2 = abs((trq1 / trq2) ** p) * abs(spd1 / spd2) * time1
                    # outputDf.loc[trq2][spd2] += time2
                    outputDf.loc[trq2, spd2] += time2
                    pCoeffient += time1 / 60 * spd1 * (abs(trq1) ** p)

            outputDf = outputDf.sort_index(axis=0, ascending=False)
            outputDf.to_excel(out_path)
            print('%s -> 对应 p= %f，对应损失当量为 = %.5e' % (out_path, p, pCoeffient))
    print('转换损失当量完成！')


def getTotalLoadSpectrum(path, mutiplyList, num):
    # 初始化容器
    dfList = []
    sheetList = []
    writer = pd.ExcelWriter(path + '/spectrum/totalSpectrum-' + str(num) + '.xlsx')

    # 统计VEHICLE总载荷谱
    files = os.listdir(path + '/spectrum/VEHICLE/')
    # files -> list[tables]
    print(files)
    tableList = []
    for file in files:
        new_path = os.path.join(path + '/spectrum/VEHICLE/' + file)
        table = pd.read_excel(new_path, index_col=0)
        tableList.append(table)
    newDf = pd.DataFrame(mutiplyList[0] * tableList[0], dtype='float32')
    # print(newDf)
    newDf.to_excel('newDftest.xlsx', sheet_name='VEHICLE')
    for i in range(1, len(mutiplyList)):
        newDf += mutiplyList[i] * tableList[i]

    dfList.append(newDf)
    sheetList.append('VEHICLE')

    # 统计DC总载荷谱
    files = os.listdir(path + '/spectrum/DC/')
    # files -> list[tables]
    print(files)
    tableList = []
    for file in files:
        new_path = os.path.join(path + '/spectrum/DC/' + file)
        table = pd.read_excel(new_path, index_col=0)
        tableList.append(table)
    newDf = pd.DataFrame(mutiplyList[0] * tableList[0], dtype='float32')
    for i in range(1, len(mutiplyList)):
        newDf += mutiplyList[i] * tableList[i]
    dfList.append(newDf)
    sheetList.append('DC')

    # 统计AC总载荷谱
    files = os.listdir(path + '/spectrum/AC/')
    # files -> list[tables]
    print(files)
    tableList = []
    for file in files:
        new_path = os.path.join(path + '/spectrum/AC/' + file)
        table = pd.read_excel(new_path, index_col=0)
        tableList.append(table)
    newDf = pd.DataFrame(mutiplyList[0] * tableList[0], dtype='float32')
    for i in range(1, len(mutiplyList)):
        newDf += mutiplyList[i] * tableList[i]
    dfList.append(newDf)
    sheetList.append('AC')

    # 统计EM总载荷谱
    files = os.listdir(path + '/spectrum/EM/')
    # files -> list[tables]
    print(files)
    tableList = []
    for file in files:
        new_path = os.path.join(path + '/spectrum/EM/' + file)
        table = pd.read_excel(new_path, index_col=0)
        tableList.append(table)
    newDf = pd.DataFrame(mutiplyList[0] * tableList[0], dtype='float32')
    for i in range(1, len(mutiplyList)):
        newDf += mutiplyList[i] * tableList[i]
    dfList.append(newDf)
    sheetList.append('EM')

    # 输出
    for i in range(len(dfList)):
        dfList[i] = dfList[i].style.set_properties(**{'text-align': 'center'})
        dfList[i].to_excel(writer, sheet_name=sheetList[i])
    writer.close()

    print('生成总路谱的载荷谱完成！')


def getTotalStatistic(path, mutiplyList):
    # 统计数据
    totalCount = 0
    for times in mutiplyList:
        totalCount += times
    statistic_path = path + '/statistic/loadSpectrumStatistic.xlsx'
    statisticDf = pd.read_excel(statistic_path, index_col=0)
    statisticDf.loc[:, 'VMean'] = statisticDf.loc[:, 'VMean'] * mutiplyList
    statisticDf.loc[:, 'SpdMean'] = statisticDf.loc[:, 'SpdMean'] * mutiplyList
    statisticDf.loc[:, 'TrqMean'] = statisticDf.loc[:, 'TrqMean'] * mutiplyList
    statisticDf.loc[:, 'ACMean'] = statisticDf.loc[:, 'ACMean'] * mutiplyList
    statisticDf.loc[:, 'DcMean'] = statisticDf.loc[:, 'DcMean'] * mutiplyList
    statisticDf.loc[:, 'ACpwrMean'] = statisticDf.loc[:, 'ACpwrMean'] * mutiplyList
    statisticDf.loc[:, 'ACpwr_L:0-50'] = statisticDf.loc[:, 'ACpwr_L:0-50'] * mutiplyList
    statisticDf.loc[:, 'ACpwr_L-M:50-100'] = statisticDf.loc[:, 'ACpwr_L-M:50-100'] * mutiplyList
    statisticDf.loc[:, 'ACpwr_M:100-150'] = statisticDf.loc[:, 'ACpwr_M:100-150'] * mutiplyList
    statisticDf.loc[:, 'ACpwr_M-H:150-200'] = statisticDf.loc[:, 'ACpwr_M-H:150-200'] * mutiplyList
    statisticDf.loc[:, 'ACpwr_H:>200'] = statisticDf.loc[:, 'ACpwr_H:>200'] * mutiplyList
    statisticDf.loc[:, 'GBpwrMean'] = statisticDf.loc[:, 'GBpwrMean'] * mutiplyList
    statisticDf.loc[:, 'GBpwr_L:0-50'] = statisticDf.loc[:, 'GBpwr_L:0-50'] * mutiplyList
    statisticDf.loc[:, 'GBpwr_L-M:50-100'] = statisticDf.loc[:, 'GBpwr_L-M:50-100'] * mutiplyList
    statisticDf.loc[:, 'GBpwr_M:100-150'] = statisticDf.loc[:, 'GBpwr_M:100-150'] * mutiplyList
    statisticDf.loc[:, 'GBpwr_M-H:150-200'] = statisticDf.loc[:, 'GBpwr_M-H:150-200'] * mutiplyList
    statisticDf.loc[:, 'GBpwr_H:>200'] = statisticDf.loc[:, 'GBpwr_H:>200'] * mutiplyList
    statisticDf.loc[:, 'Average_Eff'] = statisticDf.loc[:, 'Average_Eff'] * mutiplyList
    finalStat = [statisticDf.loc[:, 'VMin'].min(), statisticDf.loc[:, 'VMean'].sum() / totalCount,
                 statisticDf.loc[:, 'VMax'].max(),
                 statisticDf.loc[:, 'SpdMin'].min(), statisticDf.loc[:, 'SpdMean'].sum() / totalCount,
                 statisticDf.loc[:, 'SpdMax'].max(),
                 statisticDf.loc[:, 'TrqMin'].min(), statisticDf.loc[:, 'TrqMean'].sum() / totalCount,
                 statisticDf.loc[:, 'TrqMax'].max(),
                 statisticDf.loc[:, 'ACMin'].min(), statisticDf.loc[:, 'ACMean'].sum() / totalCount,
                 statisticDf.loc[:, 'ACMax'].max(),
                 statisticDf.loc[:, 'DcMin'].min(), statisticDf.loc[:, 'DcMean'].sum() / totalCount,
                 statisticDf.loc[:, 'DcMax'].max(),
                 statisticDf.loc[:, 'ACpwrMin'].min(), statisticDf.loc[:, 'ACpwrMean'].sum() / totalCount,
                 statisticDf.loc[:, 'ACpwrMax'].max(), statisticDf.loc[:, 'ACpwr_L:0-50'].sum() / totalCount,
                 statisticDf.loc[:, 'ACpwr_L-M:50-100'].sum() / totalCount,
                 statisticDf.loc[:, 'ACpwr_M:100-150'].sum() / totalCount,
                 statisticDf.loc[:, 'ACpwr_M-H:150-200'].sum() / totalCount,
                 statisticDf.loc[:, 'ACpwr_H:>200'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwrMin'].min(), statisticDf.loc[:, 'GBpwrMean'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwrMax'].max(), statisticDf.loc[:, 'GBpwr_L:0-50'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwr_L-M:50-100'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwr_M:100-150'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwr_M-H:150-200'].sum() / totalCount,
                 statisticDf.loc[:, 'GBpwr_H:>200'].sum() / totalCount,
                 statisticDf.loc[:, 'Average_Eff'].sum() / totalCount, ]
    statisticDf.drop(statisticDf.index[0:], inplace=True)
    statisticDf.loc['finalStat'] = finalStat

    statisticDf.to_excel(path + '/statistic/finalLoadSpectrumStatistic.xlsx')
    print('总统计完成！')


if __name__ == '__main__':
    print('test')
    trq1 = -100
    spd1 = 6000
    trq2 = -150
    spd2 = 9000
    time1 = 32012
    time2 = abs((trq1 / trq2) ** 3) * abs(spd1 / spd2) * time1
    print(time2)
